/*
 * @lc app=leetcode.cn id=599 lang=cpp
 *
 * [599] 两个列表的最小索引总和
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <unordered_map>

using namespace std;
// @lc code=start
class Solution {
public:
    vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
        unordered_map<string,int> m;
        vector<string> ret;
        int min_index = INT32_MAX;
        for(int i = 0;i < list1.size();i++) {
            for(int j = 0;j < list2.size();j++) {
                if(list1[i] == list2[j]) {
                    m.insert(make_pair(list1[i],i+j));
                    min_index = min(min_index,i+j);
                }
            }
        }
        for(unordered_map<string, int>::iterator it = m.begin();it != m.end();it++) {
            if(it->second == min_index) {
                ret.push_back(it->first);
            }
        }
        return ret;
    }
};
// @lc code=end

